package com.server.config;

import com.comm.config.TopicRabbitConfig;
import com.comm.result.ResponseResult;
import com.rabbitmq.client.Channel;
import com.server.message.RabbitMqMsgHandle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Description: TODO rabbit mq receiver listener(consumer 消费者)
 * @Author: mis_wu
 * @Date: 2022/7/29
 **/
@Slf4j
@Component
@RabbitListener(queues = TopicRabbitConfig.BUSINESS_TOPIC_KEY)
public class RabbitTopicMsgReceiverListener {

    @Value("${spring.application.name}")
    private String appName;

    @RabbitHandler
    public void process(ResponseResult<Object> receiveMsg) {
        log.info("当前消费者服务:{},rabbitmq topic 消费者收到消息:{}",appName,receiveMsg.getData());
        RabbitMqMsgHandle.setReceiveMessage(receiveMsg);
    }

    /**
     * 写法二
     * @param message msg
     * @param channel chan
     */
    @RabbitListener(queues = TopicRabbitConfig.BUSINESS_TOPIC_KEY )
    public void receiveMsg(Message message, Channel channel){
        //需要根据具体的消息体内容转换
        log.info("接收到business服务的消息：{}",message.getBody());
    }


}
